﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThuVien;
using System.Data;

namespace TranTekBE.KPI_NhanSu
{
    public partial class Gui_Yeu_Cau_Chuyen_Ca_Lam : PageRequireLogin
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Load JS
            ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "LoadJS", "LoadJS();", true);
            if (!IsPostBack)
            {
                txtUserLogin.Text = UserInfo.LastName + UserInfo.FirstName;
                FunctionsUtils.GetDropListStore(droplist_cua_hang_lam_viec);
            }
        }

        protected void btnAddYeuCau_Click(object sender, EventArgs e)
        {
            string name_user = UserInfo.UserName;
            string cua_hang_dang_lam_viec = droplist_cua_hang_lam_viec.SelectedValue.ToString();
            int ca_lam_viec = Convert.ToInt32(radio_btn_ca.SelectedValue.ToString());
            DateTime ngay_dang_lam_viec = Convert.ToDateTime(txtNgay_dang_lam_viec.Text.ToString());
            string ly_do = txtareaLyDo.Text;
            string sql_add_yeu_cau_chuyen_ca = @"
                                    INSERT INTO tbl_YeuCauChuyenCa
                                    (NAME_USER,CA_DANG_LAM,NGAY_DANG_LAM,CUA_HANG_DANG_LAM,LY_DO)
                                    VALUES
                                    ('" + name_user + "',"
                                                + ca_lam_viec + ",'"
                                                + txtNgay_dang_lam_viec.Text.ToString() + "','"
                                                + cua_hang_dang_lam_viec + "',N'"
                                                + ly_do + "'"
                                                + ")";
            try
            {
                // Insert yêu cầu chuyển ca
                FunctionsUtils.Database2.ExecuteNonQuery(sql_add_yeu_cau_chuyen_ca);
                lbSusess.Text = "Thành Công!";
                lbSusess.ForeColor = System.Drawing.Color.Red;
                txtNgay_dang_lam_viec.Text = "";
                txtareaLyDo.Text = "";
                droplist_cua_hang_lam_viec.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                ltrErr.Text = ex.Message;
                ltrErr.ForeColor = System.Drawing.Color.Red;
            }

            
        }
       
    }
}